<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style: none;
        }
        .topbar{
            width: 100%;
            height: 40px;
            background-color: black;
        }
        .header{
            width: 100%;
            height: 90px;
            background-color: red;
        }
        .nav{
            width: 100%;
            height: 60px;
            background-color: blue;
        }
        .banner{
            width: 100%;
            height: 470px;
            background-color: yellow;
            opacity: 0.5;
        }
        .conent{
            width: 100%;
            height: 2000px;
            background-color: #ccc;
        }
        .footer{
            width: 100%;
            height: 200px;
            background-color: black;
        }
        .fixednav{
            width: 100%;
            height: 60px;
            background-color: aqua;
            position: fixed;
            top:-60px;
            left: 0;
            transition: all 1s ease;
        }
        .rigtnav{
            width: 60px;
            height: auto;
            background-color: #fff;
            position: absolute;
            top:800px;
            right: 20px;
            padding: 0 10px;
            box-sizing: border-box;

        }
        .rigtnav li{
            height: 60px;
            padding-top:10px ;
            box-sizing: border-box;
        }
        .rigtnav li.backtop{
            display: none;
        }
        html{
            scroll-behavior: smooth;
        }

    </style>
</head>
<body>
    <div class="topbar"></div>
    <div class="header"></div>
    <div class="nav"></div>
    <div class="banner"></div>
    <div class="conent"></div>
    <div class="footer"></div>

    <div class="fixednav">顶部导航</div>
    <div class="rigtnav">
        <ul>
            <li>京东秒杀</li>
            <li>频道广场</li>
            <li>为您推荐</li>
            <li class="backtop">返回顶部</li>
        </ul>
    </div>
    <script>
        // 当页面卷进去的距离大于 conent块距页面顶部的偏移量时，让,fixednav 从上面滑下来
        //  window.pageYoffset     docuemnt.doceuntElement.scrollTop
        // banner.offsetTop

        //1.查
      var conent=  document.querySelector('.conent');
      var fixednav=  document.querySelector('.fixednav');
      var rigtnav=  document.querySelector('.rigtnav');
      var backtop=  document.querySelector('.backtop');
      window.onscroll=function(){
        var j= window.pageYOffset;
        var t= conent.offsetTop;
         if(j>t){
            fixednav.style.top='0px';
            rigtnav.style.position='fixed';
            rigtnav.style.top='80px';
            backtop.style.display='block'

         }else{
            fixednav.style.top='-60px';
            rigtnav.style.position='absolute';
            rigtnav.style.top=conent.offsetTop+'px';
            backtop.style.display='none'
         }

      }

      backtop.onclick=function(){
        document.documentElement.scrollTop=0;

      }

    //  window.scrollTo(x,y)
    </script>
</body>
</html>